<template>
  <div class="box">
    <div v-if="proDetailList.order_id || proDetailList.type">
      <van-nav-bar title="订单详情" @click-left="onClickLeft" left-arrow></van-nav-bar>
      <div class="orderDetaile_box">
        <div class="orderDetail_title">
          <p>爱美售后均在爱美APP内进行，通过微信/电话联系您以各种理由进行支付宝转账或点击链接退款均为诈骗！请勿将此订单信息截图给可疑人员。</p>
        </div>
        <h4 v-if="orderDetailList.status === '0'">订单未支付</h4>
        <h4 v-else>订单已完成</h4>
        <div class="orderDetail_pro" @click="toProDetail(orderDetailList.proid)">
          <img :src="proDetailList.pro_pic" alt="">
          <div class="orderDetail_pro_right">
            <p>{{proDetailList.pro_introduce}}</p>
            <p>{{'已选择 ' + proDetailList.type + ' 项目'}}</p>
            <p>预付款: <span>{{'￥' + orderDetailList.pro_price}}</span></p>
            <p>{{'商品数量: x' + orderDetailList.pro_num}}</p>
          </div>
        </div>
        <div class="orderDetail_text">
          <span>预付款总计：</span>
          <span class="orderDetail_text_color">{{'￥' + orderDetailList.pro_price}}</span>
        </div>
        <div class="orderDetail_text">
          <span>优惠总计：</span>
          <span class="orderDetail_text_color">{{'-￥' + orderDetailList.pro_coupons}}</span>
        </div>
        <div class="orderDetail_text">
          <span>预留手机号：</span>
          <span>{{username}}</span>
        </div>
        <div class="orderDetail_text">
          <span>备注信息：</span>
          <span>{{orderDetailList.pro_remark}}</span>
        </div>
        <div v-if="orderDetailList.status === '0'" class="orderDetail_footer">
          <p>
            合计：
            <span>{{'￥' + (orderDetailList.pro_price - orderDetailList.pro_coupons)}}</span>
          </p>
          <p>
            <span @click="cancelOrder">取消订单</span>
            <span @click="payOrder">去支付</span>
          </p>
        </div>
        <div v-else class="orderDetail_footer">
          <p>
            合计：
            <span>{{'￥' + (orderDetailList.pro_price - orderDetailList.pro_coupons)}}</span>
          </p>
          <p>
            <span @click="delOrder">删除订单</span>
          </p>
        </div>
      </div>
    </div>
    <Loading v-else />
  </div>
</template>

<script>
import Loading from '../../components/loading'
import { getProductById, getOrderDetail, getWelfareProDetailList, delOrder } from '../../api'
import Vue from 'vue'
import { NavBar, Icon, Dialog, Toast } from 'vant'
Vue.use(NavBar)
Vue.use(Icon)
Vue.use(Dialog)
Vue.use(Toast)
export default {
  data () {
    return {
      orderDetailList: {},
      username: localStorage.getItem('userTel_AM'),
      proDetailList: [],
      order_id: ''
    }
  },
  components: {
    Loading
  },
  mounted () {
    this.order_id = this.$route.query.order_id
    // const order_id = this.$route.query.order_id
    getOrderDetail({
      username: localStorage.getItem('userTel_AM'),
      order_id: this.order_id
    }).then(res => {
      if (res.data.code === '200') {
        this.orderDetailList = res.data.data[0]
        const proid = this.orderDetailList.proid
        if (this.orderDetailList.proid.substring(0, 2) === '10') {
          getProductById({
            proid,
            username: localStorage.getItem('userTel_AM')
          }).then(res => {
            if (res.data.code === '200') {
              this.proDetailList = res.data.data[0]
            }
          })
        } else {
          getWelfareProDetailList({ proid }).then(res => {
            this.proDetailList = res.data.data[0]
          })
        }
      }
    })
  },
  methods: {
    onClickLeft () {
      this.$router.go(-1)
    },
    toProDetail (proid) {
      this.$router.push({ path: '/proDetail', query: { proid } })
    },
    delOrder () {
      Dialog.confirm({
        message: '你确定要删除订单吗'
      })
        .then(() => {
          delOrder({
            username: localStorage.getItem('userTel_AM'),
            order_id: this.order_id
          }).then(res => {
            if (res.data.code === '200') {
              Toast('订单已删除')
              setTimeout(() => {
                this.$router.replace('/myOrder')
              }, 300)
            }
          })
        })
        .catch(() => {
          // on cancel
        })
    },
    cancelOrder () {
      Dialog.confirm({
        message: '你确定要取消订单吗'
      })
        .then(() => {
          delOrder({
            username: localStorage.getItem('userTel_AM'),
            order_id: this.order_id
          }).then(res => {
            if (res.data.code === '200') {
              Toast('订单已取消')
              setTimeout(() => {
                this.$router.replace('/myOrder')
              }, 300)
            }
          })
        })
        .catch(() => {
          // on cancel
        })
    },
    payOrder () {
      this.$router.replace({ path: '/payOrder', query: { order_id: this.order_id } })
    }
  }
}
</script>

<style lang="scss" scoped>
.orderDetaile_box {
  height: 100%;
  .orderDetail_title {
    width: 100%;
    height: 0.4rem;
    padding: 0.07rem 0.2rem;
    background:rgba(250,250,250,1);
    p {
      font-size: 0.1rem;
      color: #464646;
      line-height: 0.13rem;
    }
  }
  h4 {
    margin-top: 0.1rem;
    width: 100%;
    height: 0.4rem;
    padding: 0 0.2rem;
    line-height: 0.4rem;
    color: #464646;
    font-size: 0.18rem;
    font-weight: normal;
    border-bottom: 1px solid #f2f2f2;
  }
  .orderDetail_pro {
    padding: 0.16rem 0.2rem;
    width: 100%;
    height: 1.25rem;
    background: #fbfbfb;
    border-bottom: 1px solid #f2f2f2;
    img {
      width: 0.93rem;
      height: 0.93rem;
      float: left;
      margin-right: 0.1rem;
    }
    .orderDetail_pro_right {
      width: 2.32rem;
      height: 0.93rem;
      float: left;
      p:nth-of-type(1) {
        line-height: 0.2rem;
        height: auto;
        font-size: 0.18rem;
        color: #464646;
        display: -webkit-box;
        text-overflow: ellipsis;
        overflow : hidden;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        margin-bottom: 0.15rem;
      }
      p:nth-of-type(2) {
        line-height: 0.12rem;
        height: 0.12rem;
        font-size: 0.12rem;
        color: #464646;
        margin-bottom: 0.15rem;
      }
      p:nth-of-type(3) {
        line-height: 0.10rem;
        height: 0.10rem;
        font-size: 0.10rem;
        color: #9C9C9C;
        margin-bottom: 0.15rem;
        float: left;
        span {
          color: #ff6b6b;
        }
      }
      p:nth-of-type(4) {
        line-height: 0.10rem;
        height: 0.10rem;
        font-size: 0.10rem;
        color: #9C9C9C;
        float: right;
      }
    }
  }
  .orderDetail_text {
    width: 100%;
    height: 0.4rem;
    padding: 0 0.2rem;
    line-height: 0.4rem;
    border-bottom: 1px solid #f2f2f2;
    span:nth-of-type(1) {
      float: left;
    }
    span:nth-of-type(2) {
      float: right;
    }
    .orderDetail_text_color {
      color: #ff6b6b;
    }
  }
  .orderDetail_footer {
    width: 100%;
    height: 0.46rem;
    position: fixed;
    bottom: 0;
    padding: 0 0.2rem;
    p:nth-of-type(1) {
      float: left;
      color: #9C9C9C;
      line-height: 0.46rem;
      font-size: 0.14rem;
      span {
        color: #ff6b6b;
      }
    }
    p:nth-of-type(2) {
      float: right;
      span:nth-of-type(1) {
        display: inline-block;
        width: 0.72rem;
        height: 0.26rem;
        border: 1px solid #f2f2f2;
        text-align: center;
        line-height: 0.26rem;
        margin: 0.1rem 0;
        border-radius: 0.04rem;
        font-size: 0.14rem;
      }
      span:nth-of-type(2) {
        display: inline-block;
        margin: 0.1rem 0 0.1rem 0.1rem;
        width: 0.72rem;
        height: 0.26rem;
        line-height: 0.26rem;
        font-size: 0.14rem;
        color: white;
        text-align: center;
        border-radius: 0.04rem;
        background: #fa91de;
      }
    }
  }
}
/deep/ .van-icon-arrow-left {
  font-size: 0.22rem;
  color: #171717;
}
/deep/ .van-nav-bar__title {
  font-size: 0.18rem;
  color: #171717;
  font-weight: bold;
}
/deep/ .van-nav-bar {
  z-index: 1000;
}
</style>
